package com.yunfei.config;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.context.refresh.ContextRefresher;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import java.util.Set;
/**
 * @program: 通过@Autowired注入ContextRefresher，作一个定时任务，定时调用contextRefresher.refresh()
 * @description:远程仓库配置文件更新之后，自动刷新配置
 * @author: zhengyunfei
 * @create: 2019-07-11 15:11
 **/
@Component
public class AutoRefreshScope {
    @Autowired
    private ContextRefresher contextRefresher;
    //每5分钟执行一次
    @Scheduled(cron = "${jobs.schedule}")
    public void refresh(){
        try{
            Set<String> result = contextRefresher.refresh();
        }catch (Exception e){

        }

        //System.err.println(result);
    }
}
